import { createSelector } from '@ngrx/store';

import { getResourceTreeState } from './resource-tree.selector';
import { ResourceTreeState, OwnState } from '../reducers';

import { TreeItem, TreeviewItem } from '../../components';

const getOwnState = createSelector(getResourceTreeState, (state: ResourceTreeState) => state.own);
const getAllOwns = createSelector(getOwnState, (state: OwnState) => state.data);
const getAllOwnsToTreeview = createSelector(getAllOwns, (data: TreeItem[]) => {
    return data.map((treeItem: TreeItem) => new TreeviewItem(treeItem));
});
const getOwnLoaded = createSelector(getOwnState, (state: OwnState) => state.loaded);
const getOwnLoading = createSelector(getOwnState, (state: OwnState) => state.loading);

export const ownSelectors = {
    getOwnState,
    getAllOwns,
    getAllOwnsToTreeview,
    getOwnLoaded,
    getOwnLoading
};